package com.example.tool.service.logisticstrajectory;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tool.bean.business.wdt.LogisticsTrajectoryDO;
import com.example.tool.mapper.LogisticsTrajectoryMapper;
import com.example.tool.util.ExpressDeliveryUtil.ExpressDeliveryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogisticsTrajectoryServiceImpl extends ServiceImpl<LogisticsTrajectoryMapper, LogisticsTrajectoryDO> implements LogisticsTrajectoryService {
    @Autowired
    LogisticsTrajectoryMapper logisticsTrajectoryMapper;

    @Override
    public LogisticsTrajectoryDO logisticsNoByItem(String logisticsNo) {
        QueryWrapper<LogisticsTrajectoryDO> query = new QueryWrapper<>();
        query.eq("logistics_no", logisticsNo);
        List<LogisticsTrajectoryDO> list = logisticsTrajectoryMapper.selectList(query);
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public void markMonitor(String logisticsNo) {
        LogisticsTrajectoryDO logisticsTrajectoryDO = logisticsNoByItem(logisticsNo);
        if (ObjectUtil.isNotNull(logisticsTrajectoryDO) && !logisticsTrajectoryDO.getIfMonitor()) {
            ExpressDeliveryUtil.trackSubSubscribe(logisticsNo);
        }
    }
}
